package cn.tedu.jdbc.util;

import java.sql.*;

public class JDBCUtil {

    static{
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        String url = "jdbc:mysql:///cgb2104?characterEncoding=utf8";
        Connection conn  = DriverManager.getConnection(url, "root", "root");
        return conn;
    }

    public static void close(ResultSet rs, Statement stmt,Connection conn) throws SQLException {
        if(rs!=null)
            rs.close();
        if(stmt!=null)
            stmt.close();
        if(conn!=null)
            conn.close();
    }
}
